/*
This file is part of buco.  
Copyright (c) 2012 Christopher Pawelzik <christopher@cpawelzik.com>

Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 
*/ 
package buco.http;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import buco.core.api.BundleComposition;
import buco.core.api.CompositionContext;

public class SessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		// Session will be timed out after 30 minutes inactivity
		event.getSession().setMaxInactiveInterval(30*60);
		System.out.println("New Session created."); 
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		Object objCompositionCtx = event.getSession().getAttribute(JsonRpcServlet.compositionSessionKey);
		if(objCompositionCtx != null) {
			System.out.println("Session Destroyed, close composition."); 
			CompositionContext ctx = (CompositionContext) objCompositionCtx; 
			ctx.close();			
		}		
	}
}
